<template>
  <el-page-header @back="handleBack">
    <template #icon>
      <el-icon>
        <ArrowLeft />
      </el-icon>
    </template>
    <template #content>
      <span class="text-large font-600 mr-3">加入医生团队</span>
    </template>
  </el-page-header>
  <el-table :data="joinedTeamForm" style="width: 100%" class="team-table">
    <el-table-column fixed prop="id" label="编号" width="100" />
    <el-table-column prop="teamName" label="团队名称" width="200" />
    <el-table-column prop="leaderName" label="团队队长" width="100" />
    <el-table-column prop="label" label="团队标签" width="200" >
      <template #default="scope">
        <div class="team-label-container">
              <span v-for="(tag,index) in scope.row.label.split(',')" :key="index" class="team-tag">
                {{tag}}
              </span>
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="orgName" label="所属机构" width="250" />
    <el-table-column prop="count" label="签约人数" width="120" />
    <el-table-column prop="status" label="状态" width="120" >
      <template #default="scope">
            <span :class="scope.row.status === 1 ? 'status-active' : 'status-inactive'">
      {{ scope.row.status === 1 ? '启用中' : '禁用中' }}
    </span>
      </template>
    </el-table-column>
    <el-table-column fixed="right" label="操作" min-width="120">
      <template #default="scope">
        <el-button link type="primary" size="small" @click="joinTeam(scope.row.id)">
          加入
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { ArrowLeft } from "@element-plus/icons-vue";
import {findAllTeam} from "../api/SysTeam.js";
import {addDoctorTeamMember} from "../api/SysDoctorTeam.js";

export default {
  name: "JoinTeam",
  components: {
    ArrowLeft
  },
  data() {
    return {
      joinedTeamForm:[],
      doctorId: "",
      teamId: "",
    };
  },
  methods: {
    handleBack() {
      this.$router.go(-1);
    },
    async loadData() {
      let {data:data}=await findAllTeam({ doctorId: this.doctorId })
      console.log( data)
      this.joinedTeamForm = data.data;
    },
    async joinTeam(row){
      console.log("加入团队，ID：", row)
      let {data:data}=await addDoctorTeamMember( this.doctorId, row)
      this.$router.go(-1);
    }
  },
  created() {
    this.doctorId = this.$route.query.doctorId;
    this.loadData();
  }
};
</script>

<style scoped>
.text-large {
  font-size: 16px;
}

.font-600 {
  font-weight: 600;
}
</style>